import RequestError from 'libs/RequestError'

it('should could create RequestError right', () => {
  const status = 200
  const statusText = 'OK'
  const requestError = new RequestError(status, statusText)

  expect(requestError.name).toBe('RequestError')
  expect(requestError.status).toBe(status)
  expect(requestError.statusText).toBe(statusText)
})

it('should could create RequestError right with default statusText', () => {
  const status = 200
  const requestError = new RequestError(status)

  expect(requestError.status).toBe(status)
  expect(requestError.statusText).toBe('Request Error')
})

it('should call formatErrorMessage to format error messsages', () => {
  const status = 200
  const statusText = 'OK'
  const requestError = new RequestError(status, statusText)

  expect(requestError.formatErrorMessage()).toBe(`${status} ${statusText}`)
})

it('should call formatErrorMessage to format error messsages when passing `errors`', () => {
  const status = 200
  const statusText = 'OK'
  const errors = ['error1', 'error2']
  const requestError = new RequestError(status, statusText, errors)

  expect(requestError.formatErrorMessage()).toBe(errors.join('\n'))
})

it('should handle errors as string', () => {
  const status = 200
  const statusText = 'OK'
  const errors = 'error'
  const requestError = new RequestError(status, statusText, errors)

  expect(requestError.formatErrorMessage()).toBe(errors)
})
